package 数据结构OJ;

/**
 * @author shy_black
 * @date 2019/6/26 10:59
 * @Description:
 * 判断是否为镜像二叉树
 */
public class 对称的二叉树 {

    class TreeNode {
        int val = 0;
        TreeNode left = null;
        TreeNode right = null;

        public TreeNode(int val) {
            this.val = val;

        }

    }

    boolean isSymmetrical(TreeNode pRoot) {
        if (pRoot == null)
            return true;
        return isSymmetrical(pRoot.left, pRoot.right);
    }

    boolean isSymmetrical(TreeNode left, TreeNode right) {
        if (left == null && right == null) {
            return true;
        }
        if (left != null && right != null)
            return left.val == right.val && isSymmetrical(left.left, right.right) && isSymmetrical(left.right, right.left);
        else
            return false;
    }
}